/// @tags: Polya
#include <cstdio>
#include <iostream>

using namespace std;

namespace BlueQuantum {

typedef long long ll;

int const P = 1e9 + 7;

int T, n;

inline ll qpow(ll base, int exp) {
  ll res = 1;
  while (exp) {
    if (exp & 1) res = res * base % P;
    base = base * base % P;
    exp >>= 1;
  }
  return res;
}

int phi(int x) {
  int res = x;
  for (int i = 2; i * i <= x; ++i) {
    if (x % i == 0) {
      res = res - res / i;
      while (x % i == 0) x /= i;
    }
  }
  if (x != 1) res = res - res / x;
  return res;
}

inline int main() {
  cin >> T;
  while (T--) {
    cin >> n;
    ll ans = 0;
    for (int i = 1; i * i <= n; ++i) {
      if (n % i == 0) {
        if ((ans += qpow(n, i) * phi(n / i) % P) >= P) ans -= P;
        if (i * i != n) {
          if ((ans += qpow(n, n / i) * phi(i) % P) >= P) ans -= P;
        }
      }
    }
    cout << ans * qpow(n, P - 2) % P << '\n';
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("Pólya.in", "r", stdin);
  freopen("Pólya.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
